package com.nf.web;
 
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nf.entity.ProductEntity;
import com.nf.service.ProductServiceImpl;
@WebServlet("/product/insert")
public class ProductInsertServlet extends HttpServlet{
 
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ObjectMapper mapper=new ObjectMapper ();
		ProductEntity product=mapper.readValue(req.getInputStream(),ProductEntity.class);
		
		ProductServiceImpl productService=new ProductServiceImpl();
		Object result=null;
		try {
			result = productService.insert(product);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		resp.setContentType("application/json;charset=UTF-8");
		resp.getWriter().println(result);
	}

}
